package cn.laixueit.controller;

import cn.laixueit.base.R;
import cn.laixueit.pojo.Datadictionart;
import cn.laixueit.pojo.DatadictionartDetail;
import cn.laixueit.service.DatadictionartService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author duxiang
 * @date 2023/12/25 13:55
 */
@RestController
@RequestMapping("/dataDictionArt")
public class DataDictionController {
    @Resource
    private DatadictionartService datadictionartService;

    @GetMapping("/getDataDictionList")
    public R getDataDictionMap(String dataDictartCodes){
        List<Datadictionart> list = datadictionartService.getDataDictionArtList(dataDictartCodes);
        return R.ok().put("rows",list);
    }

    @GetMapping("/getDataDictionMapList")
    public R getDataDictionMapList(String dataDictartCodes){
        Map<String, LinkedList<DatadictionartDetail>> mapList = datadictionartService.getDataDictionArtMapList(dataDictartCodes);
        return R.ok().put("map",mapList);
    }

    @PostMapping("save")
    public R save(@RequestBody Datadictionart datadictionart){
        datadictionartService.saveDatadictionart(datadictionart);
        return R.ok();
    }

    @PostMapping("saveChildrenDataDict")
    public R saveChildrenDataDict(@RequestBody DatadictionartDetail datadictionartDetail){
        datadictionartService.saveDatadictionartDetail(datadictionartDetail);
        return R.ok();
    }

    @PostMapping("page/{page}/{pageSize}")
    public R page(@PathVariable("page") Integer page,
                  @PathVariable("pageSize") Integer pageSize,
                  @RequestBody Datadictionart datadictionart){
        Page<Datadictionart> pageInfo = new Page<>(page, pageSize);
        return datadictionartService.pageDatadictionart(pageInfo,datadictionart);
    }

    @GetMapping("/getDataDictDetails/{dataDictCode}")
    public R getDataDictDetails(@PathVariable("dataDictCode") String dataDictCode){
        return datadictionartService.getDataDictDetails(dataDictCode);
    }

    @DeleteMapping("/deleteDatadictByCode")
    public R deleteDatadictByCode(@RequestParam String dataDictCode){
        return datadictionartService.deleteDatadictByCode(dataDictCode);
    }

    @DeleteMapping("/deleteDatadictDetailByCode")
    public R deleteDatadictDetailByCode(@RequestParam String dataDictCode){
        return datadictionartService.deleteDatadictDetailByCode(dataDictCode);
    }

}
